Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

mikkel pohjola
mikkel pohjola
1,966 Points

i need help for this video here: PHP CRUD Operations with PHP-Creating Records- Reading Project Data

i cant get the data from the database, so i am thinking that you are using another form of database the mysql.

How do i connect to mysql database so i can retrive my data

Dave StSomeWhere
Dave StSomeWhere
19,870 Points

Where is the data you'd like to retrieve, do you have a local environment with MySQL?

mikkel pohjola
mikkel pohjola
1,966 Points

Yes i use a local mysql database

Dave StSomeWhere
Dave StSomeWhere
19,870 Points

OK Mikkel,

It would help to know how you set up your local instance of MySQL - what's your OS, are you using something like XAMPP or WAMP or MAMP?

Here's the steps that are pretty much global - just let me know if you need additional detail or have any questions:

  1. Check your phpinfo() and verify you have the MySQL PDO extension enabled (probably should verify MySQLi also)
  2. Check the server name in phpMyAdmin (should be at top of page - breadcrumbs) - usually "localhost"
  3. Create a database - remember the database name (create tables as desired).
  4. Select the database in phpMyAdmin and go to Priviledges
  5. Select Add User Account (you much have a database specific user to connect)
  6. Create a User with "grant all privileges on db...")
  7. Note your Username and Password (needed for connection)
  8. Now you can create a db connection - using your values below:
<?php
$user = 'your Username'
$pass = 'your Password'
$dbh = new PDO('mysql:host=localhost;dbname=yourdb', $user, $pass);
?>
  1. Next steps - execute PDO stuff - check the manual for details

1 Answer

mikkel pohjola
mikkel pohjola
1,966 Points

Hi Dave I am using mamp and i am using a Windows 10 computer. I Will check tomirrow, what you have sendt to me and ser og i Can get it to work ?