unixodbc with php command works but apache2 fail - php

I've installed unixodbc, freetds, php on Ubuntu 12.04.4 LTS (GNU/Linux 3.8.0-44-generic i686) and I get my query works fine with:
php /var/www/connect.php
but when access to localhost/connect.php I get:
Warning: odbc_connect(): SQL error: [unixODBC][Driver Manager]Data source name not found, and no default driver specified, SQL state IM002 in SQLConnect in /var/www/connect.php on line 8 Warning: odbc_exec() expects parameter 1 to be resource, boolean given in /var/www/connect.php on line 10 Warning: odbc_fetch_row() expects parameter 1 to be resource, null given in /var/www/connect.php on line 11 Warning: odbc_close() expects parameter 1 to be resource, boolean given in /var/www/connect.php on line 15
I think is about permissions.

Related

odbc_connect problem with mdbtools and unixodbc

I would like to acccess a mdb file in a windows machine (windows server 2003) from a linux machine (centos 6.10)
Im using mdbtools and unixodbc
so far what i did
odbc.ini
[mydatabase]
Driver = MDBTools
Description = Microsoft Access Try DB
Servername = localhost
Database =/mnt/example.mdb
UserName =Admin
Password =
port = 5432
odbcinst.ini
[MDBTools]
Description = MDBTools Driver
Driver64 = /usr/lib64/libmdbodbc.so.0
Setup64 = /usr/lib64/libmdbodbc.so.0
FileUsage = 1
UsageCount = 1
i check the connection using isql in terminal
isql -v mydatabase
and it returns connected
i can query the database successfully
by using query like this
select * from units
right now i want to connect the access database using php
test4.php
<?php
error_reporting(E_ALL); ini_set('display_errors', 1);
$myDB = odbc_connect("mydatabase","Admin","");
$query = "select * from units";
$result = odbc_exec($myDB, $query);
$report = odbc_fetch_row($result);
echo odbc_result($result, 1);
odbc_close($myDB);
?>
i received this error
Warning: odbc_connect(): SQL error: Failed to fetch error message, SQL state HY000 in SQLConnect in /var/www/test/test4.php on line 6
Warning: odbc_exec() expects parameter 1 to be resource, boolean given in /var/www/test/test4.php on line 11
Warning: odbc_fetch_row() expects parameter 1 to be resource, null given in /var/www/test/test4.php on line 12
Warning: odbc_result() expects parameter 1 to be resource, null given in /var/www/test/test4.php on line 13
Warning: odbc_close() expects parameter 1 to be resource, boolean given in /var/www/test/test4.php on line 15
im currently using
PHP Version 7.2.28
mySQL Version 5.7.29

Issue running code sniffer on Mac

I am trying to install php code sniffer. I have manage to get to a point where after running
php /Users/ryanfernandes/pear/bin/phpcs --version it display the info. but when I try to run code sniffer by
php /Users/username/pear/bin/phpcs /Users/username/development/htdocs/test.php
PHP Warning: fwrite() expects parameter 1 to be resource, boolean given in /Users/username/pear/share/pear/PHP/CodeSniffer/Reporting.php on line 155
Warning: fwrite() expects parameter 1 to be resource, boolean given in /Users/username/pear/share/pear/PHP/CodeSniffer/Reporting.php on line 155
PHP Warning: stream_get_meta_data() expects parameter 1 to be resource, boolean given in /Users/username/pear/share/pear/PHP/CodeSniffer/Reporting.php on line 206
Warning: stream_get_meta_data() expects parameter 1 to be resource, boolean given in /Users/username/pear/share/pear/PHP/CodeSniffer/Reporting.php on line 206
PHP Warning: file_get_contents(): Filename cannot be empty in /Users/username/pear/share/pear/PHP/CodeSniffer/Reporting.php on line 208
Warning: file_get_contents(): Filename cannot be empty in /Users/username/pear/share/pear/PHP/CodeSniffer/Reporting.php on line 208
PHP Warning: fclose() expects parameter 1 to be resource, boolean given in /Users/username/pear/share/pear/PHP/CodeSniffer/Reporting.php on line 209
Warning: fclose() expects parameter 1 to be resource, boolean given in /Users/username/pear/share/pear/PHP/CodeSniffer/Reporting.php on line 209
Any help would be really appreciated.
Thanks
From the error messages, it looks like you are using PHP_CodeSniffer version 1.5.4. PHP_CodeSniffer uses the tmpfile() function to create a temporary file. The directory that it is created in can be found by running:
php -r 'echo sys_get_temp_dir().PHP_EOL;'
Make sure you are allowed to write to that directory because the tmpfile() method is obviously returning FALSE, which most commonly happens if the directory is not writable.

Returning warning error

http://go.wlg.co.nz/login.php
I had a page working fine and I swear I didn't change anything. Now its returning this:
Warning: mysql_connect() [function.mysql-connect]: Can't connect to
local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in
/home/content/93/10501493/html/go/connect.php on line 15
Warning: mysql_select_db() expects parameter 2 to be resource, boolean
given in /home/content/93/10501493/html/go/connect.php on line 16
Warning: mysql_real_escape_string() expects parameter 2 to be
resource, boolean given in /home/content/93/10501493/html/go/login.php
on line 16
Warning: mysql_real_escape_string() expects parameter 2 to be
resource, boolean given in /home/content/93/10501493/html/go/login.php
on line 17
Warning: mysql_close() expects parameter 1 to be resource, boolean
given in /home/content/93/10501493/html/go/connect.php on line 18
Anything obvious jumps out?
Make sure mysql service is running
service mysqld start
Or
Are you connecting to "localhost" or "127.0.0.1" ? when you connect to "localhost" the socket connector is used, but when you connect to "127.0.0.1" the TCP/IP connector is used. You could
try using "127.0.0.1" if the socket connector is not enabled/working.

Connecting to database with ODBC results in warnings and nothing printed

I am trying to use ODBC with php and I seem to be having some problems. This is my code:
<?php
$connect = odbc_connect("digitallibrary", "root", "");
$sql = "SELECT name FROM books";
$result = odbc_exec($connect, $sql);
echo $result;
while (odbc_fetch_row($result)) {
$name = odbc_result($result, "name");
print("$name\n");
}
odbc_close($connect);
?>
I have also installed mysql odbc connector and added this system DSN:
Datasource Name : digitallibrary
TCP/IP Server: localhost Port 80
user: root
database:digitallibrary
When I run my code I get this warnings but nothing printed:
Warning: odbc_connect(): SQL error: [Microsoft][ODBC Driver Manager] The specified DSN contains an architecture mismatch between the Driver and Application, SQL state IM014 in SQLConnect in E:\Program Files\xampp\htdocs\DigitalLibrary\index.php on line 9
Warning: odbc_exec() expects parameter 1 to be resource, boolean given
in E:\Program Files\xampp\htdocs\DigitalLibrary\index.php on line 11
Warning: odbc_fetch_row() expects parameter 1 to be resource, null
given in E:\Program Files\xampp\htdocs\DigitalLibrary\index.php on
line 14
Warning: odbc_close() expects parameter 1 to be resource, boolean
given in E:\Program Files\xampp\htdocs\DigitalLibrary\index.php on
line 18
what am I doing wrong?
Now, You are attempting to use a 64 bit application with a 32 bit ODBC driver or vice versa. You should check that what are you using the PHP application 64 bit or 32 bit. After that you have to start the correct ODBC administrator. There are 2 types which are 32 bit and and 64 bit.
If you are using 64 bit ODBC administrator: It is in Adminstrative tools, control panel
If you are using 32 bit ODBC administrator: You should go into the path %windir\syswow64\odbcad32.exe.
When you have set the right ODBC administrator. You will also need to create the system DSN. If you cannot find the MS Access driver in the administrator you'll need to download one for that architecture.
EDIT : you can download the 32 bit from here
Hope this helps.

Bake Models - CakePHP - Ubuntu

I am currently trying to bake models for a project in CakePHP. I have set up my database tables and baked my skeleton project. I then execute the following via terminal:
cake bake -app /home/gary/glecto/
Which then display's me the correct menu. When I choose "M" I get the following error
PHP Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /usr/share/php/cake/libs/model/datasources/dbo/dbo_mysql.php on line 540
Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /usr/share/php/cake/libs/model/datasources/dbo/dbo_mysql.php on line 540
PHP Warning: mysql_select_db() expects parameter 2 to be resource, boolean given in /usr/share/php/cake/libs/model/datasources/dbo/dbo_mysql.php on line 546
Warning: mysql_select_db() expects parameter 2 to be resource, boolean given in /usr/share/php/cake/libs/model/datasources/dbo/dbo_mysql.php on line 546
PHP Warning: mysql_get_server_info() expects parameter 1 to be resource, boolean given in /usr/share/php/cake/libs/model/datasources/dbo/dbo_mysql.php on line 554
Warning: mysql_get_server_info() expects parameter 1 to be resource, boolean given in /usr/share/php/cake/libs/model/datasources/dbo/dbo_mysql.php on line 554
PHP Warning: mysql_query() expects parameter 2 to be resource, boolean given in /usr/share/php/cake/libs/model/datasources/dbo/dbo_mysql.php on line 588
Warning: mysql_query() expects parameter 2 to be resource, boolean given in /usr/share/php/cake/libs/model/datasources/dbo/dbo_mysql.php on line 588
Your database does not have any tables.
Does anyone have any ideas on how I could solve this? I've been scratching my head for hours.
EDIT
Connection code
class DATABASE_CONFIG {
var $default = array(
'driver' => 'mysql',
'persistent' => false,
'host' => 'localhost',
'port' => 3306,
'login' => 'root',
'password' => '',
'database' => 'glectoMVC',
);
}
Also - If I look at the cakePHP generated startup page it confirms that my database connection is OK.
Managed to figure it out:
Apparently CakePHP isn't too happy with localhost as a host name. Instead I changed it to 127.0.0.1
Sup dude. this does look like mysql isn't running. Mainly as it's stating a can't connect and not a credentials fail. What LAMPP Stack are you running?
If all else fails and the LAMPP app you're using states the process is running successfully, ensure you haven't two instances of mysql running asynchronously.

Categories