Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,148,479 members, 7,801,205 topics. Date: Thursday, 18 April 2024 at 12:24 PM

How Do I Connect To Mysql! - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / How Do I Connect To Mysql! (666 Views)

Help With Image Uploading To Mysql Database + Like System / Creating A Group Chat With Html/javascript/php/mysql For Beginners / I Changed My Password From Myphpadmin And Can No Longer Connect To Mysql Server (2) (3) (4)

(1) (Reply) (Go Down)

How Do I Connect To Mysql! by emmanuelatas(m): 5:43am On May 01, 2015
I'm gradually learning php and mysql and it has been a problem connecting to mysql with the mysql_connect(). How do I connect to a database name "test" and table name "members". Help of out. Thanks for your input.
Re: How Do I Connect To Mysql! by Nobody: 6:05am On May 01, 2015
emmanuelatas:
I'm gradually learning php and mysql and it has been a problem connecting to mysql with the mysql_connect(). How do I connect to a database name "test" and table name "members". Help of out. Thanks for your input.

Mysql_connect("localhost", "database username", "databasepassword"];

Mysql_select_db("test"];
Re: How Do I Connect To Mysql! by umaryusuf(m): 6:45am On May 01, 2015
You should have posted the code u hv written so far, the php version u are using. There several ways to achieve this;-

For latest version of MySQLi (improved):
<?php
$servername = "localhost";
$username = "username";
$password = "password";

// Create connection
$conn = new mysqli($servername, $username, $password);

// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>

NOTE
-----
This "MySQL" extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQL extension should be used.
Re: How Do I Connect To Mysql! by FRInteractives: 9:02am On May 01, 2015
Here's how to create a mysql database connection using PDO
<?php
$dsn = 'mysql:dbname=testdb;host=127. 0.0.1'; $user = 'dbuser'; $password = 'dbpass'; try { $dbh = new PDO ($dsn, $user, $password); } catch (PDOException $e) { echo 'Connection failed: ' . $e- >getMessage(); } ?>

1 Like

(1) (Reply)

Xpath Injection / Admission In Western European Ukraine National University. / Freelance Graphic Designer Available

(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. 7
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.