Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

PHP 

Mysql Help - Hooking up php to mysql

Just need some help with setting up mysql. I've got the hosting, server, website, bot, database.. only need aid with getting mysql properly hooked up.

If anyone can help please pm.

This is for a csgo jackpot website.
What do you mean "hooked up"? It should already work. All you'll need is your database user and password.
Code
<?php
$username = "x";
$password = "y";
$hostname = "z";

$dbhandle = mysql_connect($hostname, $username, $password)
  or die("Unable to connect to MySQL");
?>
That will connect to the database. Then you need more code on the bottom to further interact with it.
(Dec 20, 2015 10:51 PM)NON- Wrote:  What do you mean "hooked up"? It should already work. All you'll need is your database user and password.
Code
<?php
$username = "x";
$password = "y";
$hostname = "z";

$dbhandle = mysql_connect($hostname, $username, $password)
  or die("Unable to connect to MySQL");
?>
That will connect to the database. Then you need more code on the bottom to further interact with it.

That is one approach but mysql_ is deprecated, use mysqli_ or PDO (PHP Data Objects).

For PDO:

PHP Code

<?php 
$dbh 
= new PDO('mysql:host=localhost;dbname=test', $user, $pass); 

PDO Docs: http://php.net/manual/en/pdo.connections.php
the way i like to do it is create a db.php so if the details of youre database everchange, all you have to do is edit this file, not the rest.

in db.php this is the code

Code
<?php
$db = mysqli_connect("host", "username", "password", "database");
?>


Now on all youre pages you want youre database to connect to just add

Code
include_once("db.php")


Possibly Related Threads...
Thread / Author Replies Views Last Post
[PHP] by jamesgates1Jul 20, 2014 04:33 PM 8 307 Jul 20, 2014 04:33 PM
Last Post: jamesgates1
[PHP] by Ciel PhantomhiveApr 6, 2014 08:01 AM 3 418 Apr 6, 2014 08:01 AM
Last Post: svensonic1
[PHP] by Dir50Jul 16, 2013 06:59 AM 2 121 Jul 16, 2013 06:59 AM
Last Post: Dir50