Ask coding questions

← Back to all posts
PHP and MySQLi
Lightcaster5 (13)

I don't know if it is simply disabled on repl.it or I am doing something wrong but I cannot connect to my SQL database through my PHP files. This is what I am currently doing:

$DB_SERVER = 'server_here';
$DB_USERNAME = 'username_here';
$DB_PASSWORD = 'password_here';
$DB_NAME = 'name_here';
 
$mysqli = new mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
 
// Check connection
if($mysqli === false){
    die("ERROR: Could not connect. " . $mysqli->connect_error);
} else {
  echo '<p>Connected</p>';
}

But whenever I run the page with the connection script I get the following error:

Uncaught Error: Class 'mysqli' not found in my-project-here

Answered by malvoliothegood (845) [earned 5 cycles]
View Answer
Comments
hotnewtop
malvoliothegood (845)

Seems debatable whether you can do what you ask. Here is a comment I came across by Googling: https://repl.it/talk/ask/How-do-I-use-a-database-with-the-new-php-server/15708

Lightcaster5 (13)

@malvoliothegood I don't believe you understand my post; I am asking whether or not it is possible and IF SO, what am I doing wrong/where can I go to learn how to achieve my goal?

malvoliothegood (845)

@Lightcaster5 I think I understood what you meant. My answer said I don't think you can do this and I included a link to an old conversation that basically said this. If you find an answer that lets you do such a hook up let me know. All the best.

Lightcaster5 (13)

@malvoliothegood Thanks, after a bit of testing and using echo phpInfo(); I've found that $pdo = new PDO(Stuff here); works but throws an exception because there are No Drivers Found and in phpInfo(); under the PDO section it says No Value for where it is saying if drivers are enabled. Thanks for the help!

malvoliothegood (845)

@Lightcaster5 Thanks for the info. You can easily develop using PHP, and MySql applications using the XAMPP, WAMP or LAMP packages. I have used the first two in the past and built a WordPress site locally before hosting it on the web. I have also used it to teach programming and relational databases when I was a teacher.