How to get data from mySQL and insert it in Array?
Posted: Thu May 20, 2004 6:42 am
My mySQL table is on one server but PHP file which I want insert some info from this mySQL table is on another server. And also I need insert this information into Array in PHP file.
I know how to conect to mySQL server and how to get info from there and write it but I do not know how to insert it into Array in PHP file spesially when there is already some info in this Array from before.
So actually I need to update my Array with new info from mySQL table.
Here is what I got so far:
<?php
/* Connecting, selecting database */
$link = mysql_connect("www.domain.com:80/", "user", "pass")
or die("Could not connect : " . mysql_error());
echo "Connected successfully";
mysql_select_db("helpdemo_xcart") or die("Could not select database");
/* Performing SQL query */
$query = "SELECT * FROM xcart_customers";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
/* Inserting results in to PHP file */
$line = mysql_fetch_array($result, MYSQL_ASSOC)) ;
$toSave = $line;
//Open a file in write mode
$fp = fopen("test4/file.txt", "w");
if(fwrite($fp, $line)) echo "writing=Ok";
else echo "writing=Error";
fclose($fp);
/* Free resultset */
mysql_free_result($result);
/* Closing connection */
mysql_close($link);
?>
So I need to update my Array with new info from mySQL table.
any advices are welcome
Thanks a lot!
I know how to conect to mySQL server and how to get info from there and write it but I do not know how to insert it into Array in PHP file spesially when there is already some info in this Array from before.
So actually I need to update my Array with new info from mySQL table.
Here is what I got so far:
<?php
/* Connecting, selecting database */
$link = mysql_connect("www.domain.com:80/", "user", "pass")
or die("Could not connect : " . mysql_error());
echo "Connected successfully";
mysql_select_db("helpdemo_xcart") or die("Could not select database");
/* Performing SQL query */
$query = "SELECT * FROM xcart_customers";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
/* Inserting results in to PHP file */
$line = mysql_fetch_array($result, MYSQL_ASSOC)) ;
$toSave = $line;
//Open a file in write mode
$fp = fopen("test4/file.txt", "w");
if(fwrite($fp, $line)) echo "writing=Ok";
else echo "writing=Error";
fclose($fp);
/* Free resultset */
mysql_free_result($result);
/* Closing connection */
mysql_close($link);
?>
So I need to update my Array with new info from mySQL table.
any advices are welcome
Thanks a lot!