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 trialmikkel pohjola
1,966 Pointsi 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
mikkel pohjola
1,966 PointsYes i use a local mysql database
Dave StSomeWhere
19,870 PointsOK 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:
- Check your phpinfo() and verify you have the MySQL PDO extension enabled (probably should verify MySQLi also)
- Check the server name in phpMyAdmin (should be at top of page - breadcrumbs) - usually "localhost"
- Create a database - remember the database name (create tables as desired).
- Select the database in phpMyAdmin and go to Priviledges
- Select Add User Account (you much have a database specific user to connect)
- Create a User with "grant all privileges on db...")
- Note your Username and Password (needed for connection)
- 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);
?>
- Next steps - execute PDO stuff - check the manual for details
1 Answer
mikkel pohjola
1,966 PointsHi 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 ?
Dave StSomeWhere
19,870 PointsDave StSomeWhere
19,870 PointsWhere is the data you'd like to retrieve, do you have a local environment with MySQL?