Skip to main content

Posts

Showing posts with the label mysql

What should every PHP programmer know?

I would like to be a PHP/MySQL programmer What are the technologies that I must know? Like: Frameworks IDEs Template Engines Ajax and CSS Frameworks Please tell me the minimum requirements that I must know, and tell me your favourite things in the previous list? Thanks

Send data from android to mysql using php

I have a some text on an android client, I want to send it to the database(MySQL). How do I do this.Please help me with this. I tried using php and Mysql. Is the query in Php right?? Here is what I have tried Insert.java public class Insert extends ListActivity { String[] ct_name = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // setContentView(R.layout.main); InputStream is = null; // http post ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(new BasicNameValuePair("c_name","KL")); try{ HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://10.0.2.2/city1.php"); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); is = enti

Send data from android to mysql using php

I have a some text on an android client, I want to send it to the database(MySQL). How do I do this.Please help me with this. I tried using php and Mysql. Is the query in Php right?? Here is what I have tried Insert.java public class Insert extends ListActivity { String[] ct_name = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // setContentView(R.layout.main); InputStream is = null; // http post ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(new BasicNameValuePair("c_name","KL")); try{ HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://10.0.2.2/city1.php"); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); is = enti

My first web-based iPhone application - how to do it right?

I've built my first web-based iPhone app and I have some performance issues that I needs to be resolved. I want to verify that I'm doing it right, so your feedback is really appreciated... :-) The application presenting data - images & text directly from my remote MySQL DB using PHP based web-services. I'm using the SDWebImage for lazy-downloading. Now, I wonder if I'm doing everything right or is there something needs to be modified for better performance - Each connection to the DB is handling via NSMutableURLRequest using POST method. It's running again if I receive time-out connection from the DB and displaying an alert-view if connection fails. There is only one PHP web-service for every operation - I mean - if, for instance, I'm running the remote getInfo.php script for fetching information from my DB to be presented on info-view-controller, there is only one copy of this script on my web-site, so everyone's ru

Remotely accessing web server, and connecting to local mysql (via php)

I am trying to connect to my local mysql server via php. so my code looks as follows: $con = mysql_connect("localhost", "user", "password"); mysql_select_db("database", $con) or die('ERROR 4'); ok, we've all seen that before. So when I run this PHP script on the machine with the mysql database, everything runs fine. But once I access this script remotely (on the server, with the local mysql database) it cannot connect to the database. Is there any way to make it so the PHP code connects to the mysql database via a local reference? Or do I need to look into connecting to the mysql database through an IP address? edit: To clarify, when I access the script on the server from somewhere else, it doesn't work edit 2: When I check the error log it states "Call to undefined function mysql_connect()"

Subquery returns more than 1 row

All I have two table 1st table is : wp_frm_item_metas 2nd table is : wp_frm_items Now i want to meta_value based on wp_frm_items table fields value. I fired this sql. it returns me Subquery returns more than 1 row SELECT meta_value FROM wp_frm_item_metas WHERE (item_id=( SELECT id FROM wp_frm_items WHERE form_id ='9' && user_id='1') && field_id=128) I tried this solution SELECT meta_value FROM wp_frm_item_metas WHERE (item_id=( SELECT count(*) as c,id FROM wp_frm_items WHERE form_id ='9' && user_id='1') && field_id=128 && c > 1) ORDER BY c DESC It returns this error Operand should contain 1 column(s) My code is foreach($fp_id_c as $kid=>$id) { if (!$id or ($logged_in && !$user_ID)) return; $id = (int)$id; //echo $logged_in.'-'.(int)$user_ID; if ($logged_in){

How to place an "inline image&rdquo; in form before upload?

I want to allow users to write a post and upload images inline through out it (like a CMS blog post). Writing the file upload script is easy. But allowing a "place inline" button / functionality is proving to be tricky. Is there a tutorial on how to do this? I'm messing around with some javascript to allow it. Also, I'm not sure if I should display the inline tmp image or actually upload the file (with a separate upload button than the full form upload button) and show the actual image loc before the form is submitted? I'm all over the place on this right now. How should I go about this? Thank you.

database design for tracking the location. NEED HELP!! :(

im currently doing the database design for an android app like friend finder. im doing the coding in java and i'l be using google maps to display the location. location is tracked using gps. the functionality would be: -locate u n all ur friends on the map -give alerts when a friend is somewhere close like within 5km -hide users location from certain people. this is what ive come up with so far.. location ---------- location id location name user --------- user id and rest of the details friendlist ------------ userid friendid distance_frm_user users_location [visible, nt visible] type [friend, rejected] if the user accepts a friend request then 2 rows r created in the friendlist table one with userid=1 and friendid=2 second with userid=2 and friendid=1 and the attribute "type" in the friendlist wud be set to friend for both the rows in the friendlist table. users_location is set to visible if the user wants that friend to see his location. my ques

PHP query does not return result

This query is not returning any result as there seems to be an issue with the sql. $sql = "select region_description from $DB_Table where region_id='".$region_id."' and region_status =(1)"; $res = mysql_query($sql,$con) or die(mysql_error()); $result = "( "; $row = mysql_fetch_array($res); $result .= "\"" . $row["region_description"] . "\""; while($row = mysql_fetch_array($res)) { echo "<br /> In!"; $result .= " , \"" . $row["region_description"] . "\""; } $result .= " )"; mysql_close($con); if ($result) { return $result; } else { return 0; } region_id is passed as 1. I do have a record in the DB that fits the query criteria but no rows are returned when executed. I beleive the issue is in this part , region_id='".$region_id."' so on using the gettype function in my php it turns out that the datatype of reg

special character like " not showing properly in pdf

I using html2fpdf library to generate a pdf in codeigniter .I have some data in a varchar field like " What are your child’s academic strengths? " which is showing like " What are your child’s academic strengths? " . How I can show it as it is in the database .(I have tried htmlspecialchars_decode , html_entity_decode function but it not worked. )

About the BLOB datatype in MySQL

I have stored an image in MySQL using the BLOB datatype. I am able to retrieve image through JSP but when I use Chrome or Firefox browser I am unable to view the image. It is displaying in an encrypted format. Can anyone please help me?

matching outputted Html buttons with outputted Php/MySQL data

public function dcr() { $query = $this->db->query("SELECT * FROM church_repo"); foreach ($query->result() as $row) { $data = array('churchName' => $row->church_name, 'streetAddress' => $row->street_address, 'locationalState' => $row->locational_state, 'locationalZIP' => $row->locational_zip, 'locationalCountry' => $row->locational_country, 'locationalCity' => $row->locational_city, 'overseerAccountId' => $row->overseer_account_id, 'taxExemptionNumber' => $row->tax_exemption_number, 'accountStatus' => $row->status, ); $this->load->view('admin-request', $data); } } I

Converting MySQL to PDO

I've been advised a couple of times on here to start changing my code to PDO and I've finally got round to doing it. My problem is that I'm having incredible difficulty with converting my existing login script. For the last few lines of the code below (after the line $result = $query->fetchAll(); ) I haven't been able to find any resources online that could help me re-write it: $username = $_POST['username']; $password = $_POST['password']; $db=getConnection(); $username = mysql_real_escape_string($username); $query = $db->prepare( "SELECT password, salt, 'employer' as user_type FROM JB_Employer WHERE Username = '$username' UNION SELECT password, salt, 'jobseeker' as user_type FROM JB_Jobseeker WHERE User_Name = '$username'"); $result = $query->fetchAll(); $qData = mysql_fetch_array($result, MYSQL_ASSOC); $hash = hash('sha256', $qData['salt'] . hash('sha256', $password) ); if (

INNER JOIN not working properly

I have a problem with a mysql join i'm trying to complete. This is my code: SELECT title, books.`author_id`, books.`publisher_id`, books.`format_id`, books.`genre_id`, pages, isbn, description, DATE_FORMAT(release_date, '%M, %d, %Y') FROM `books` INNER JOIN `authors` ON (`authors`.`author_id`= `books`.`author_id`) INNER JOIN `publishers` ON (`publishers`.`publisher_id`= `books`.`publisher_id`) INNER JOIN `formats` ON (`formats`.`format_id`= `books`.`format_id`) INNER JOIN `genres` ON (`genres`.`genre_id`= `books`.`genre_id`)` authors, publishers, formats and genres are all separate tables each with two columns. author_id and author in the case of the authors table, and the same format for the others. The join doesn't seem to work no matter what i do, please help me to see where i've gone wrong.

Database error after moving website?

I just moved my website from a test domain to the actual domain and I changed the DB info in the PHP script, but I'm still getting an error even though I triple-checked that I have the correct database, host, username and password. Am I missing something? This is the code I use to connect. The database info is definitely correct. $dbhost = "localhost"; $dbuser = "username"; $dbpass = "password"; function dbConnect($db='dbname') { global $dbhost, $dbuser, $dbpass; $dbcnx = @mysql_connect($dbhost, $dbuser, $dbpass) or die('Database problem.'); if ($db!='' and !@mysql_select_db($db)) die('Database not available at the moment. Please try again in a couple of minutes.'); return $dbcnx; } And then I call the function dbConnect('dbname') from the script. The error I get is the second error from the code above, "Database not available at the moment. Please try again in a couple o

Does storing large sessions slow down response time and server

I am in the process of creating a Facebook App for my website which includes functionality that requires the users friends list. Retrieving the friends is no problem, what I am struggling to decide, is how to store them. Option 1 - Store the users in my MySQL database, I have opted not to go for this as my database will become very heavy, very quickly. In addition, I will need to create a table for each individual Facebook user! Option 2 - Store the Facebook friends array in a session which is updated every half an hour to ensure new friends are included. Ignore the fact that the session updates every half an hour, is it a bad idea to store, what can be a very large array, within a session? The website is likely to be receiving high volumes of traffic, and will therefore be storing a lot of these sessions. Although I am an experienced developer, I am not overly experienced with sessions in these circumstances. I would simply like to know whether or not this i

Backup MySql Database?

I have asked this question before but I haven't got an answer, so I'm rephrasing it. I want to back up a db using either: system("mysqldump -h DB_HOST -u DB_USER -p DB_PASS logindb > $location/$backup"); or: sql="BACKUP my_db TO DISK my_backup_folder WITH FORMAT #"; if ($stmt = $this->connect->prepare($sql)) { $stmt->execute(); $stmt->close(); } else { $error = true; $message['error'] = true; $message['message'] = CANNOT_PREPARE_DATABASE_CONNECTION_MESSAGE; return json_encode($message); } But the first gives me an empty sql file and the second gives me nothing. Why is that, and if there is a way to find out what error occurred how would I do it ? Also which method is better ?

PHP read file error

I need to get an end result which loads a txt file counts how many times each word has been used and echos the results. The code is used is given below.Looking forward for valuable suggestions... <?php $text = fopen("words.txt", "r"); $textarray = explode(" ",$text); foreach($textarray as $numbers) { if(isset($str_count[$numbers])) $str_count[$numbers]++; else $str_count[$numbers]=1; } foreach($str_count as $words => $numbers) echo $words.": ".$numbers."<br>"; ?>