Page 1 of 1

PHP-Database connect

Posted: Fri Jan 18, 2008 6:30 pm
by outjack
I am trying to connect to a MySQL database with the following code:
I have not had any success so far. Please help me out.

*** PLEASE USE THE

Code: Select all

TAG *****[/color]

Code: Select all

<?php
 
echo ("something!");
 
$link = mysql_connect("localhost","james","james","testDB") or die(mysqli_connect_error());
 
if(mysqli_connect_errno())
{
    printf("Connection failed: %s\n", mysqli_connect_error());
    exit();
}
else
{
    $sql = "insert into testtbl(firstName) values('christine')";
    $result = mysql_query($link, $sql);
    
    if($result == TRUE)
    {
        echo "a record has been inserted.";
    }
    else
    {
        printf("Could not insert record: %s\n",mysql_error($link));
    }
    
    mysql_close($link);
}
?>
The line " echo "something!" " is displays output which tells me that PHP and apache are working fine. However, I cant seem to get through to the database please help me out.

Re: PHP-Database connect

Posted: Fri Jan 18, 2008 6:52 pm
by Christopher
You are using the mysql_connect() to connect and the mysqli_*() fuctions for errors. They are two different libraries.