cdogstu99 Posted December 24, 2009 Share Posted December 24, 2009 So i built a website in ASP a while ago, and used connection strings to connect to a database in Microsoft Access. My connection string looked like this in the page where i would display data from the table: <% ' Name of the Accessdb being read accessdb="database/pricelist2.mdb" ' Connect to the db with a DSN-less connection cn="DRIVER={Microsoft Access Driver (*.mdb)};" cn=cn & "DBQ=" & server.mappath(accessdb) ' Create a server recordset object Set rs = Server.CreateObject("ADODB.Recordset") ' Select specific fields from the table the_bird sql = "SELECT Coin1, Coin2, Coin3, Coin4, Coin5, Coin6, Coin7, Coin8, Coin9 FROM contact;" ' Execute the sql rs.Open sql, cn %> But now i just need some help on how to connect to the Access database using PHP and Linux Based Hosting. Can anyone help? Quote Link to comment https://forums.phpfreaks.com/topic/186202-switching-from-asp-to-phpneed-help-connecting-to-access-database/ Share on other sites More sharing options...
trq Posted December 24, 2009 Share Posted December 24, 2009 Do you have odbc support on your server. Check the output of phpinfo to see. Your probably better off moving your application to a proper database anyway, but yeah, odbc is what your looking for. Quote Link to comment https://forums.phpfreaks.com/topic/186202-switching-from-asp-to-phpneed-help-connecting-to-access-database/#findComment-983385 Share on other sites More sharing options...
cdogstu99 Posted December 24, 2009 Author Share Posted December 24, 2009 Thanks! So you are recommending using a mysql database? Quote Link to comment https://forums.phpfreaks.com/topic/186202-switching-from-asp-to-phpneed-help-connecting-to-access-database/#findComment-983399 Share on other sites More sharing options...
trq Posted December 24, 2009 Share Posted December 24, 2009 Over access? Definitely. I used to be an asp developer, you've gotta let that stuff go Quote Link to comment https://forums.phpfreaks.com/topic/186202-switching-from-asp-to-phpneed-help-connecting-to-access-database/#findComment-983401 Share on other sites More sharing options...
premiso Posted December 24, 2009 Share Posted December 24, 2009 Thanks! So you are recommending using a mysql database? I would second Thorpe's suggestion. But if you are stuck on ASP stuff, SQLServer is way better then access as well. Access is just...well its own little demon. If you are switching to Linux / PHP, definitely switch to MySQL as well. And yea, I used to develop in ASP / SQLServer / VB C# too. But my boss used SQLServer, which was way better then access. I still hated coding in VB when I had to though. Quote Link to comment https://forums.phpfreaks.com/topic/186202-switching-from-asp-to-phpneed-help-connecting-to-access-database/#findComment-983468 Share on other sites More sharing options...
cdogstu99 Posted December 24, 2009 Author Share Posted December 24, 2009 Thanks guys, so i have decided to switch over to mysql based on your recommendations. I created a simple table with two fields, coin and price. But i'm trying to just connect to the database (using godaddy hosting) and nothing is showing up. Maybe someone can help with my string or page to see if something looks off?? Here's my page: <?php //Connect To Database $hostname='getliquid.db.4760604.hostedresource.com'; $username='getliquid'; $password='********'; $dbname='getliquid'; $usertable='contact'; $yourfield = 'coin'; mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.'); mysql_select_db($dbname); $query = 'SELECT * FROM $usertable'; $result = mysql_query($query); if($result) { while($row = mysql_fetch_array($result)){ $name = $row['$yourfield']; echo 'Name: '.$name; } } ?> Here's the page (As you can see nothing is showing up); http://startuplab.net/wordpress/contact_test.php Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/186202-switching-from-asp-to-phpneed-help-connecting-to-access-database/#findComment-983737 Share on other sites More sharing options...
mrMarcus Posted December 24, 2009 Share Posted December 24, 2009 $query = 'SELECT * FROM $usertable'; your $usertable variable (or any variable for that matter) will not parse when within single-quotes. two options: 1. [concatenation] $query = 'SELECT * FROM ' . $usertable; 2. (most common practice) [code]$query = "SELECT * FROM $usertable";[/code] Quote Link to comment https://forums.phpfreaks.com/topic/186202-switching-from-asp-to-phpneed-help-connecting-to-access-database/#findComment-983739 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.