Problem setting up connection to MySQL
Posted: Mon Mar 17, 2014 3:41 am
Hey guys and gals,
I am a noobie to programming and these boards so first greetings
to everyone. I started learning html/css/php/mysql a couple of weeks ago and think I am progressing nicely but as I got into databases I started having some set up problems. A couple of stats:
Mac OSX Mountain Lion
XAMPP 1.8.3-3
PHP 5.5.9.
I am learning from TheNewBoston tutorials and all the code from their videos there worked fine - untill I tried connecting to a database with mysql_connect function. Sometimes it worked, sometimes it didnt but after a while I learned about the deprecated functions and the new mysqli class. This is what I am trying to do - I have a file called "connect.inc.php" where I have my connection stored (is this neccessary at all?) and another one called "databases.php" where I experiment with SQL querries. I created my test database with PHP MyAdmin.
Connect.inc.php
Databases.php
THE PROBLEM
First time I created and saved this, it worked (in Chrome); the message displayed was "Connected to database probna." Then I decided to play around with values stored in variables user, pass and host to see if I can produce some errors and if it's really connected to where I want it to connect. I changed the "root" to "skjdhsjdhf" and this is the message I got upon trying to load "connection.inc.php":
Fatal error: Class 'mysqli_connect' not found in /Applications/XAMPP/xamppfiles/htdocs/probniphp/connect.inc.php on line 9
When I try to load "databases.php" I get two messages:
Warning: include(1): failed to open stream: No such file or directory in /Applications/XAMPP/xamppfiles/htdocs/probniphp/databases.php on line 21
Warning: include(): Failed opening '1' for inclusion (include_path='.:/Applications/XAMPP/xamppfiles/lib/php') in /Applications/XAMPP/xamppfiles/htdocs/probniphp/databases.php on line 21
I believe this is something trivial but I am just starting out so please dont be harsh on me
. I'd like to move on to more coding but IM stuck hee since yesterday
Cheers all!
I am a noobie to programming and these boards so first greetings
Mac OSX Mountain Lion
XAMPP 1.8.3-3
PHP 5.5.9.
I am learning from TheNewBoston tutorials and all the code from their videos there worked fine - untill I tried connecting to a database with mysql_connect function. Sometimes it worked, sometimes it didnt but after a while I learned about the deprecated functions and the new mysqli class. This is what I am trying to do - I have a file called "connect.inc.php" where I have my connection stored (is this neccessary at all?) and another one called "databases.php" where I experiment with SQL querries. I created my test database with PHP MyAdmin.
Connect.inc.php
Code: Select all
<?php
$host = "localhost";
$user = "root";
$pass = "";
$db = "probna";
$con = new mysqli_connect($host, $user, $pass, $db);
// Check connection
if (mysqli_connect_errno($con)) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
else {
echo "Connected to database ".$db.".";
}
?>Code: Select all
<?php
include "connect.inc.php" or die();
?>First time I created and saved this, it worked (in Chrome); the message displayed was "Connected to database probna." Then I decided to play around with values stored in variables user, pass and host to see if I can produce some errors and if it's really connected to where I want it to connect. I changed the "root" to "skjdhsjdhf" and this is the message I got upon trying to load "connection.inc.php":
Fatal error: Class 'mysqli_connect' not found in /Applications/XAMPP/xamppfiles/htdocs/probniphp/connect.inc.php on line 9
When I try to load "databases.php" I get two messages:
Warning: include(1): failed to open stream: No such file or directory in /Applications/XAMPP/xamppfiles/htdocs/probniphp/databases.php on line 21
Warning: include(): Failed opening '1' for inclusion (include_path='.:/Applications/XAMPP/xamppfiles/lib/php') in /Applications/XAMPP/xamppfiles/htdocs/probniphp/databases.php on line 21
I believe this is something trivial but I am just starting out so please dont be harsh on me
Cheers all!