Connect to MySQL Database
Posted: Thu Jan 17, 2008 5:02 pm
I am having problems with my php code below:
The first line of code, "print ("something!");" is outputing to the browser which tells me php is working correctly with apache. However the rest of the code seems to be doing nothing. I am not sure if its making a connection or not. Anyone please assist.
~pickle | Please use [ syntax ] or [ code ] tags where appropriate. Your post has been modified. I also removed your database credentials.
Code: Select all
print ("something!");
$link = mysqli_connect("localhost","xxx","yyy","testDB");
if(mysqli_connect_errno())
{
printf("Connection failed: %s\n", mysqli_connect_error());
exit();
}
else
{
$sql = "insert into testtbl(firstName) values('christine')";
$result = mysqli_query($link, $sql);
if($result == TRUE)
{
echo "a record has been inserted.";
}
else
{
printf("Could not insert record: %s\n",mysqli_error($link));
}
mysqli_close($link);
}
?>~pickle | Please use [ syntax ] or [ code ] tags where appropriate. Your post has been modified. I also removed your database credentials.