Jump to content

db connection


Ruth

Recommended Posts

I'm not sure if this is where I'm supposed to post this question but I can connect to the database with command prompt, but i can't connect in my script. Here is my code could someone tell me why I can't seem to connect.

 

@ $db = new mysqli('localhost', '', '', 'client2');

 

if (mysqli_connect_errno())

{

echo 'Error: Could not connect to database. Please

try again later';

exit;

}

 

I've also tired @ $db = new mysqli('localhost', 'user', '', 'client2');

 

I've used this code before in other projects and it worked there.

Link to comment
https://forums.phpfreaks.com/topic/102558-db-connection/
Share on other sites

Yes, using root does leave a hole, simply because the password is blank. But a fresh install of MySql usually sets you up with a root username and a blank password.

 

The problem here, as I've said before, is that you're not connecting with a username or password. You're leaving them blank. a user "username" with a blank password is just as insecure as "root" with a blank password - they both have a blank password.

 

Please make sure your username and password are correct before you attempt connecting with those.

Link to comment
https://forums.phpfreaks.com/topic/102558-db-connection/#findComment-525266
Share on other sites

odbc_connect ( string $dsn , string $user , string $password [, int $cursor_type ] )

 

 

example:

 

<?php
    $db_host        = "server.mynetwork";
    $db_user        = "dbuser";
    $db_pass        = "dbpass";
    $dsn =         "DRIVER={MySQL ODBC 3.51 Driver};" . 
            "CommLinks=tcpip(Host=$db_host);" . 
            "DatabaseName=$db_name;" . 
            "uid=$db_user; pwd=$db_pass";

    odbc_connect($dsn, $db_user, $db_pass);
?> 

Link to comment
https://forums.phpfreaks.com/topic/102558-db-connection/#findComment-525267
Share on other sites

Warning: odbc_connect() [function.odbc-connect]: SQL error: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified, SQL state IM002 in SQLConnect in C:\projects\new_client\WWW\dbconnection.php on line 19

 

I don't know anything about odbc all I've ever used is mysqli or mysql

Link to comment
https://forums.phpfreaks.com/topic/102558-db-connection/#findComment-525272
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.