1

Thanks for your help in advance. I have been working on this bug for more than 12 hours now.

There is an AJAX signup form in my Heroku site which runs on MySQL and is connected to ClearDB Database. I can successfully send data to the database on my local server (MAMP). However, I cannot do the same on the server.

The requests cannot get send to the database and gets stuck at loading. Upon inspection I realise it is a PHP 500 Error.

I found the key problem in the Heroku logs. 2014-11-24T15:02:31.238493+00:00 app[web.1]: [24-Nov-2014 15:02:30 UTC] PHP Fatal error: Call to undefined function mysql_connect() in /app/index.php on line 5

Line 5 of the index.php is mysql_connect('hostname', 'username, 'password');

I have tried running php_getinfo(); and found that there is no MySQL support in the server. On a side note, I have MySQL support in my localhost.

The server php.ini paths are as such: Configuration File (php.ini) Path /app/.heroku/php/etc/php & Loaded Configuration File /app/vendor/heroku/heroku-buildpack-php/conf/php/php.ini

What should I do?

clodal
  • 1,615
  • 20
  • 33
  • Please, [don't use `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php), They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about [prepared statements](http://en.wikipedia.org/wiki/Prepared_statement) instead, and use [PDO](http://us1.php.net/pdo) or [MySQLi](http://us1.php.net/mysqli). You will also want to [Prevent SQL Injection!](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php). ***They have likely updated MySQL.*** – Jay Blanchard Nov 24 '14 at 15:17
  • 1
    Looks like those functions aren't available on their installation (and for a good reason), follow Jay Blanchard's advice and switch over to PDO/MySQLi. – Crackertastic Nov 24 '14 at 15:19
  • If there is *no* MySQL support on your server you need to ask for it or add it. – Jay Blanchard Nov 24 '14 at 15:21
  • Okay thanks so much everyone, appreciate your help. Cheers! – clodal Nov 24 '14 at 15:23

2 Answers2

0

mysql_* functions are deprecated and actually removed in the next PHP version. Check out mysqli.

0

Worth noting that you can enable mysql_* on Heroku via composer.json. This is documented in Heroku's devcenter docs on PHP support.

Also recommend you consider using a more modern MySQL library, though :)

Chris Burgess
  • 3,551
  • 3
  • 29
  • 42
  • How to enable mysql_* on Heroku via composer.json, I'm a newbie Heroku thank you. – Nho Huynh Feb 05 '18 at 10:46
  • @NhoHuynh - you need to install composer on your dev machine and then run `composer require ext-mysql`. That will generate a composer.json and composer.lock file that will signal to Heroku it needs to install the same extension you have locally. – aldefouw Apr 21 '18 at 13:32