Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,153,618 members, 7,820,194 topics. Date: Tuesday, 07 May 2024 at 11:13 AM

Problem Trying To Connect To My Database - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Problem Trying To Connect To My Database (1066 Views)

I Need To Deal With My Database. / GURUS! I Need Urgent Help With Using Php To Connect To Xampp Mysql / Please How Do I Print This Data From MY Database. MYSQL, PHP (2) (3) (4)

(1) (Reply) (Go Down)

Problem Trying To Connect To My Database by seunzone: 11:01pm On Oct 24, 2016
holla. Please if you're quite handy with PHP help out.
see this code

//create database
$connection = mysqli_connect("localhost","root",""wink;
if (!$connection){
die("Database connection failed: " . mysql_error());
}
//databas select code
$db_select = mysqli_select_db("alm",$connection);
if (!$db_select){
die("Database connection failed: " .mysql_error());
}
?>

Its a php file, l'm trying to connect to a database named alm. my localhost password is null so thats not the problem. My browser gives the following error;
Warning: mysqli_select_db() expects parameter 1 to be mysqli, string given in C:\wamp\www\alimi\databases.php on line 8
Database connection failed:
Re: Problem Trying To Connect To My Database by Nobody: 11:06pm On Oct 24, 2016
Can solve it for a fee
Re: Problem Trying To Connect To My Database by noordean(m): 11:27pm On Oct 24, 2016
seunzone:
holla. Please if you're quite handy with PHP help out.
see this code

//create database
$connection = mysqli_connect("localhost","root",""wink;
if (!$connection){
die("Database connection failed: " . mysql_error());
}
//databas select code
$db_select = mysqli_select_db("alm",$connection);
if (!$db_select){
die("Database connection failed: " .mysql_error());
}
?>

Its a php file, l'm trying to connect to a database named alm. my localhost password is null so thats not the problem. My browser gives the following error;
Warning: mysqli_select_db() expects parameter 1 to be mysqli, string given in C:\wamp\www\alimi\databases.php on line 8
Database connection failed:
The order of ur arguments to mysqli_select_db() is wrong. $connection should come before db name.

should be:
mysqli_select_db($connection,"alm"wink

It's shown clearly from the error msg.

1 Like

Re: Problem Trying To Connect To My Database by ANTONINEUTRON(m): 12:04am On Oct 25, 2016
Forget That Mysqli_select_db() i.e cancel it.
and use only
$CONNECTION = mysqli_connect("host","username","password","databasename"wink; i.e ur database name is within the mysqli_connect()
Re: Problem Trying To Connect To My Database by Whytelyon(m): 6:41am On Oct 25, 2016
In this order.

<?php
$hostname ="127.0.0.1";
$dbuser = "root";
$dbpass = "";
$db = "Salemdb";

$con = mysqli_connect($hostname, $dbuser, $dbpass, $db) or die ( 'cannot connect ') ;

// other queries go here
?>
Re: Problem Trying To Connect To My Database by noordean(m): 7:23am On Oct 25, 2016
ANTONINEUTRON:
Forget That Mysqli_select_db() i.e cancel it.

and use only

$CONNECTION = mysqli_connect("host","username","password","databasename"wink;
i.e ur database name is within the mysqli_connect()

It can be outside. it depends on what he's trying to achieve.
Re: Problem Trying To Connect To My Database by guru01(m): 7:56am On Oct 25, 2016
Noordean is right, mysqli resource is suppose to be the first parameter pass, while the other is dbname.
Re: Problem Trying To Connect To My Database by paranorman(m): 11:30am On Oct 25, 2016
The mighty PDO.. . kiss grin cool
Re: Problem Trying To Connect To My Database by ANTONINEUTRON(m): 7:31pm On Oct 25, 2016
noordean:

It can be outside. it depends on what he's trying to achieve.
yea the 'USE' command i think??
Re: Problem Trying To Connect To My Database by ANTONINEUTRON(m): 7:31pm On Oct 25, 2016
noordean:

It can be outside. it depends on what he's trying to achieve.
yea the 'USE' command i think??
Re: Problem Trying To Connect To My Database by ANTONINEUTRON(m): 7:31pm On Oct 25, 2016
noordean:

It can be outside. it depends on what he's trying to achieve.
yea the 'USE' command i think??

(1) (Reply)

Nigeria’s First ICT University Set To Take Off In 3 Months / Can Anybody Recommend An E-learning Worpress Plugin / P2P Site Web Designers, Based In Kogi, Makurdi,abuja

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 18
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.