• We've upgraded our forums. Please post any issues/requests in this thread.

phpMyAdmin and mySQL Connection

Joined
Nov 30, 2008
Messages
555 (0.17/day)
Likes
28
Location
Birmingham, England...
Processor Intel Core 2 Quad Q6600 @ 2.8GHz
Motherboard Gigabyte X48T-DQ6
Cooling Zalman 9500 LED CPU Cooler
Memory 2x 2GB Corsair DDR3 XMS3 DHX - 1600MH/PC3-12800
Video Card(s) Gigabyte HD4870 1GB
Storage 2x Seagate 320GB Barracuda (RAID 0) 3x 1TB Samsung F3, 140GB WD Maxtor (10,000rpm)
Display(s) 2x 20" LG Flatron L204WS
Power Supply Powercool 850W
Software Windows 7 Ultimate x64
#1
Hi All

I have a mySQL DB and have edited it using phpMyAdmin and woul dnow like to access it on my website... Is this the right connection code?

Code:
$connection = mysql_connect('localhost', 'admin', 'password')  or exit('Could not connect (' . mysql_errno() . '): ' . mysql_error());
Is there a way to export this code from phpMyAdmin control panel?

Thanks
 

W1zzard

Administrator
Staff member
Joined
May 14, 2004
Messages
17,072 (3.44/day)
Likes
17,990
Processor Core i7-4790K
Memory 16 GB
Video Card(s) GTX 1080
Display(s) 30" 2560x1600 + 19" 1280x1024
Software Windows 7
#2
it's easiest if you create a php function like
PHP:
function connect_db($dbname)
{
	$dbuser = "techpowerup";
  $dbpass = ""; 
  $dbhost = "dbint.techpowerup.com"; 
  
  $db = mysql_connect($dbhost, $dbuser, $dbpass) or die("Couldn't connect to Server");
  mysql_select_db($dbname, $db) or die("Couldn't select database ".$dbname);
  return $db;
}
and then call that whenever you need to use the database
 
Joined
Nov 30, 2008
Messages
555 (0.17/day)
Likes
28
Location
Birmingham, England...
Processor Intel Core 2 Quad Q6600 @ 2.8GHz
Motherboard Gigabyte X48T-DQ6
Cooling Zalman 9500 LED CPU Cooler
Memory 2x 2GB Corsair DDR3 XMS3 DHX - 1600MH/PC3-12800
Video Card(s) Gigabyte HD4870 1GB
Storage 2x Seagate 320GB Barracuda (RAID 0) 3x 1TB Samsung F3, 140GB WD Maxtor (10,000rpm)
Display(s) 2x 20" LG Flatron L204WS
Power Supply Powercool 850W
Software Windows 7 Ultimate x64
#3
Thanks wizzard... Do I need to setup $dbname in a variable outside the function?
 

FordGT90Concept

"I go fast!1!11!1!"
Joined
Oct 13, 2008
Messages
20,922 (6.24/day)
Likes
10,023
Location
IA, USA
System Name BY-2015
Processor Intel Core i7-6700K (4 x 4.00 GHz) w/ HT and Turbo on
Motherboard MSI Z170A GAMING M7
Cooling Scythe Kotetsu
Memory 2 x Kingston HyperX DDR4-2133 8 GiB
Video Card(s) PowerColor PCS+ 390 8 GiB DVI + HDMI
Storage Crucial MX300 275 GB, Seagate 6 TB 7200 RPM
Display(s) Samsung SyncMaster T240 24" LCD (1920x1200 HDMI) + Samsung SyncMaster 906BW 19" LCD (1440x900 DVI)
Case Coolermaster HAF 932 w/ USB 3.0 5.25" bay
Audio Device(s) Realtek Onboard, Micca OriGen+
Power Supply Enermax Platimax 850w
Mouse SteelSeries Sensei RAW
Keyboard Tesoro Excalibur
Software Windows 10 Pro 64-bit
Benchmark Scores Faster than the tortoise; slower than the hare.
#4
No, you could just make a connect() function with everything defined inside. The way he set it up allows him to use the same function to access many databases.
 
Joined
Nov 30, 2008
Messages
555 (0.17/day)
Likes
28
Location
Birmingham, England...
Processor Intel Core 2 Quad Q6600 @ 2.8GHz
Motherboard Gigabyte X48T-DQ6
Cooling Zalman 9500 LED CPU Cooler
Memory 2x 2GB Corsair DDR3 XMS3 DHX - 1600MH/PC3-12800
Video Card(s) Gigabyte HD4870 1GB
Storage 2x Seagate 320GB Barracuda (RAID 0) 3x 1TB Samsung F3, 140GB WD Maxtor (10,000rpm)
Display(s) 2x 20" LG Flatron L204WS
Power Supply Powercool 850W
Software Windows 7 Ultimate x64
#5
Thank you :)

May have more questions later!
 

Aquinus

Resident Wat-man
Joined
Jan 28, 2012
Messages
10,404 (4.84/day)
Likes
5,482
Location
Concord, NH
System Name Kratos
Processor Intel Core i7 3930k @ 4.2Ghz
Motherboard ASUS P9X79 Deluxe
Cooling Zalman CPNS9900MAX 130mm
Memory G.Skill DDR3-2133, 16gb (4x4gb) @ 9-11-10-28-108-1T 1.65v
Video Card(s) MSI AMD Radeon R9 390 GAMING 8GB @ PCI-E 3.0
Storage 2x120Gb SATA3 Corsair Force GT Raid-0, 4x1Tb RAID-5, 1x500GB
Display(s) 1x LG 27UD69P (4k), 2x Dell S2340M (1080p)
Case Antec 1200
Audio Device(s) Onboard Realtek® ALC898 8-Channel High Definition Audio
Power Supply Seasonic 1000-watt 80 PLUS Platinum
Mouse Logitech G602
Keyboard Rosewill RK-9100
Software Ubuntu 17.10
Benchmark Scores Benchmarks aren't everything.
#6
adodb makes a good DB abstraction layer.
http://adodb.sourceforge.net/

PHP:
include('/path/to/adodb.inc.php');
$DB = NewADOConnection('mysql');
$DB->Connect($server, $user, $pwd, $db);
Then if you're working with multiple databases, just make an array or object of NewADOConnection members. It might be wise to make $DB global as well.

PHP:
include('/path/to/adodb.inc.php');
global $DB;
$DB = new stdClass;
$DB->foo = NewADOConnection('mysql');
$DB->bar = NewADOConnection('mysql');
$DB->foo->Connect($server, $user, $pwd, $db);
$DB->bar->Connect($server, $user, $pwd, $someotherdb);
 
Last edited:
Joined
May 21, 2009
Messages
4,966 (1.59/day)
Likes
1,511
System Name i7-PC / HTPC / iMac
Processor i7 3820 / Phenom II 940
Motherboard GIGABYTE G1.ASSASSIN2 / M3A79-T Deluxe
Cooling Corsair Hydro H100i / Scythe II (HS only)
Memory G.SKILL Trident X Series 8GB (2 x 4GB) DDR3 1600mhz / 4GB DDR2 1066 (@800) Corsair Dominator
Video Card(s) GB Radeon HD 7950s 3GB / GB Radeon HD 7950s 3GB
Storage 2x 80GB Intel X-25, 2x600gb SATA, 1x1tb 5400RPM storage /1x600GB, 3x500GB,1x160,1x120 SATA
Display(s) 1x 27" Yamakasi / Vizio 42" HDTV
Case Lian Li Lancool PC-K58 / Antec 900
Audio Device(s) HT Omega Striker 7.1 / Onboard and HDMI from ATi Card
Power Supply PC Power & Cooling 750W / 610W
Software Ubuntu / Windows 8.1 Pro / OS X / PHPStorm / Gaming
#7
i like that aquinus, will be using it shortly :)
 
Joined
Nov 30, 2008
Messages
555 (0.17/day)
Likes
28
Location
Birmingham, England...
Processor Intel Core 2 Quad Q6600 @ 2.8GHz
Motherboard Gigabyte X48T-DQ6
Cooling Zalman 9500 LED CPU Cooler
Memory 2x 2GB Corsair DDR3 XMS3 DHX - 1600MH/PC3-12800
Video Card(s) Gigabyte HD4870 1GB
Storage 2x Seagate 320GB Barracuda (RAID 0) 3x 1TB Samsung F3, 140GB WD Maxtor (10,000rpm)
Display(s) 2x 20" LG Flatron L204WS
Power Supply Powercool 850W
Software Windows 7 Ultimate x64
#8
Thanks Digi
 

Aquinus

Resident Wat-man
Joined
Jan 28, 2012
Messages
10,404 (4.84/day)
Likes
5,482
Location
Concord, NH
System Name Kratos
Processor Intel Core i7 3930k @ 4.2Ghz
Motherboard ASUS P9X79 Deluxe
Cooling Zalman CPNS9900MAX 130mm
Memory G.Skill DDR3-2133, 16gb (4x4gb) @ 9-11-10-28-108-1T 1.65v
Video Card(s) MSI AMD Radeon R9 390 GAMING 8GB @ PCI-E 3.0
Storage 2x120Gb SATA3 Corsair Force GT Raid-0, 4x1Tb RAID-5, 1x500GB
Display(s) 1x LG 27UD69P (4k), 2x Dell S2340M (1080p)
Case Antec 1200
Audio Device(s) Onboard Realtek® ALC898 8-Channel High Definition Audio
Power Supply Seasonic 1000-watt 80 PLUS Platinum
Mouse Logitech G602
Keyboard Rosewill RK-9100
Software Ubuntu 17.10
Benchmark Scores Benchmarks aren't everything.
#9
I might add that phpMyAdmin isn't exactly the most secure web service. I wouldn't host it where anyone can get a hold of it. I'm assuming you're working locally on your own machine or in a virtual machine with no access to your web server externally.
 
Joined
Nov 30, 2008
Messages
555 (0.17/day)
Likes
28
Location
Birmingham, England...
Processor Intel Core 2 Quad Q6600 @ 2.8GHz
Motherboard Gigabyte X48T-DQ6
Cooling Zalman 9500 LED CPU Cooler
Memory 2x 2GB Corsair DDR3 XMS3 DHX - 1600MH/PC3-12800
Video Card(s) Gigabyte HD4870 1GB
Storage 2x Seagate 320GB Barracuda (RAID 0) 3x 1TB Samsung F3, 140GB WD Maxtor (10,000rpm)
Display(s) 2x 20" LG Flatron L204WS
Power Supply Powercool 850W
Software Windows 7 Ultimate x64
#10
It's nothing important... The only wasy I know how to test is save it from dreamweaver, upload it using filezilla, then navigate to the url!

In the end, I went for this code... Can anyone tell me (using the same SIMPLE ways i'm using) where and how I would get the password submitted from part1.html and compare it to the username?

Thanks

PHP:
<?
    $dbServer=mysql_connect ("localhost","admin","pw");
    if (!$dbServer) {echo "Failed to connect to MySQL"; exit; }
    
    mysql_select_db("a3484399_ps",$dbServer);
    
    $sql ="SELECT * FROM users";
    $sql.=" WHERE fName=\"".$_POST["searchName"]."\"";  // the space before the WHERE is critical
	
    
    $queryResult=mysql_query($sql);
    
    if (mysql_error())
    {
      echo "Problem with Query<BR>";
      echo "The following error message was returned from MySQL:<BR>";
      echo mysql_error();
      exit;
    }
    
    if (mysql_num_rows($queryResult)==0)
    {
      echo "No users with that name.";
    }
    else
    {
      while ($dbRecord=mysql_fetch_array($queryResult))
      {
        echo "Welcome ".$dbRecord["fName"]."<BR>";
				
		
      }
    }
	
	
	
 ?>
 
Last edited by a moderator:

Aquinus

Resident Wat-man
Joined
Jan 28, 2012
Messages
10,404 (4.84/day)
Likes
5,482
Location
Concord, NH
System Name Kratos
Processor Intel Core i7 3930k @ 4.2Ghz
Motherboard ASUS P9X79 Deluxe
Cooling Zalman CPNS9900MAX 130mm
Memory G.Skill DDR3-2133, 16gb (4x4gb) @ 9-11-10-28-108-1T 1.65v
Video Card(s) MSI AMD Radeon R9 390 GAMING 8GB @ PCI-E 3.0
Storage 2x120Gb SATA3 Corsair Force GT Raid-0, 4x1Tb RAID-5, 1x500GB
Display(s) 1x LG 27UD69P (4k), 2x Dell S2340M (1080p)
Case Antec 1200
Audio Device(s) Onboard Realtek® ALC898 8-Channel High Definition Audio
Power Supply Seasonic 1000-watt 80 PLUS Platinum
Mouse Logitech G602
Keyboard Rosewill RK-9100
Software Ubuntu 17.10
Benchmark Scores Benchmarks aren't everything.
#11
A: There is an edit button, use it instead of posting multiple times.

B: What does the Users table look like?

C: You would add it to the SQL query.

D: Why in the world are you using Dreamweaver? If you want to write a web application the right way, I would get virtualbox and install a basic Ubuntu Server with a LAMP stack and edit everything using VIM.

This would help with configuration if you're not familiar with debian based servers.
https://help.ubuntu.com/community/ApacheMySQLPHP

What is your knowledge level as far as PHP and SQL is concerned? I'm assuming you're new to both because of the comment next to the query saying to remember to put a space before the where.

Personally, when I have to put SQL into a variable, I do it like this.

PHP:
$sql = "
    SELECT t.*
    FROM table AS t
        JOIN some_other_table AS o
            ON (t.sharedfield = o.sharedfield)
    WHERE t.field1 = 'foobar'
";

// Or like this just plugging it right into an adodb connection.
$db->Execute("
    SELECT t.*
    FROM table AS t
        JOIN some_other_table AS o
            ON (t.sharedfield = o.sharedfield)
    WHERE t.field1 = 'foobar'
");
 
Joined
Aug 10, 2007
Messages
4,059 (1.07/day)
Likes
1,123
Location
Geneva, FL, USA
Processor Intel i5-6600
Motherboard ASRock H170M-ITX
Cooling Cooler Master Geminii S524
Memory G.Skill DDR4-2133 16GB (8GB x 2)
Video Card(s) Gigabyte R9-380X 4GB
Storage Samsung 950 EVO 250GB (mSATA)
Display(s) LG 29UM69G-B 2560x1080 IPS
Case Lian Li PC-Q25
Audio Device(s) Realtek ALC892
Power Supply Seasonic SS-460FL2
Mouse Logitech G700s
Keyboard Logitech G110
Software Windows 10 Pro
#12
It's nothing important... The only wasy I know how to test is save it from dreamweaver, upload it using filezilla, then navigate to the url!
Set up your Remote Server in Dreamweaver and check "Automatically upload files to server on save". Correctly set up, you'll just need to Ctrl+S and refresh your browser. Or if the browser was closed, F12 for Preview in Browser. Saves time and keeps your mind on the code! :D