|
Posted by jonathan.beckett on 02/14/06 15:00
Okay... for a start, you have a quote mark missing at the start of your
query.
Here's some boilerplate code that will come in handy...
// you can put these in a config file
$db_server = "locahost";
$db_name = "foo";
$db_username = "root";
$db_password = "";
// description : connects to database and returns handle
function db_connect(){
global $db_server;
global $db_name;
global $db_username;
global $db_password;
$con =@ mysql_connect($db_server,$db_username,$db_password);
if ($con!=false){
if (!(mysql_select_db($db_name,$con))){
// could not connect
}
}
return $con;
}
// how to do a connection...
$con = db_connect();
$sql = "SELECT foo FROM bar";
$result = mysql_query($sql,$con);
if ($result!=false){
if (mysql_num_rows($result)>0){
while ($row =@ mysql_fetch_array($result)){
// $row now holds an associative array of one row from your query
// i.e. do something with it
}
} else {
// no records returned
}
} else {
// problem with SQL
}
Navigation:
[Reply to this message]
|