Linking to database


(Uncle Stripe) #1

Hi folks


I try to write some php code to read data from database,



I put following code into "function printBody()"



function printBody()

{

$conn=odbc_connect('matrix','','');

if (!$conn){

exit("Connection Failed: " . $conn);

}

$sql="SELECT * FROM sq_ast_attr_val ;";

$rs=odbc_exec($conn,$sql);

odbc_close($conn);

}



And I got following information on the screen…



Fatal error: Call to undefined function odbc_connect() in /home/websites/mysource_matrix/packages/cms/sample_asset/sample_asset.inc on line 29



Did anyone can tell how to connect database please?





cheers


(Uncle Stripe) #2

OK, I try to use $conn=pg_connect("matrix");, but it is show like this:


pg_connect() [function.pg-connect]: Unable to connect to PostgreSQL server: missing "=" after "matrix" in connection info string


(Nic Hubbard) #3

What are you trying to do?


There are plenty of functions that already connect to the database and pull out info.



Have you looked at /core/include/asset_manager.inc ?


(Greg Sherwood) #4

You never need to connect to the local DB in Matrix. The connection has already been created by the time it gets to your code.


But as Nic said, you would normally use the core methods to retrieve data rather than write your own queries, but you can certainly do it. But take a look inside that file for examples of how to run queries through our DAL.