Class not found. New to PHP - php

I basically have no experience with PHP but im having a problem setting up a Cron Job update task.
It returns an error of:
Fatal error: Class 'DB' not found in /home/content/96/9092196/html/updateevents2.php on line 17
And I'm not exactly sure how to fix it.
I didn't write the code and cannot contact the guy that did but I believe it's poorly written anyway.
<?php
ini_set("include_path", ini_get("include_path") . "/usr/share/pear:/usr/local/lib/php:/usr/local/php5/lib/php/PEAR/");
//include("includes/page_start.php");
//---------------------------------------------NewFile
$dsn = array(
'phptype' => "mysql",
'hostspec' => "111.11.111.111",
'database' => "database",
'username' => "username",
'password' => "password"
);
$db = DB::connect($dsn);
if (PEAR::isError($db))
echo "error connecting to db";
Any help will be greatly appreciated
Thanks

Related

Doctrine php DBAL not working

New to doctrine php and I followed each instruction to the point. Downloaded doctrine using composer as instructed on http://www.doctrine-project.org/projects/dbal.html and then on my index.php I added this http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#getting-a-connection only changing the test database credentials.
include_once 'vendor/autoload.php';
$config = new \Doctrine\DBAL\Configuration();
$connectionParams = array(
'dbname' => 'teastdb',
'user' => 'root',
'password' => '',
'host' => 'localhost',
'driver' => 'pdo_mysql',
);
$conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config);
and this does not work (shows blank page, I even inserted both right and wrong credential for testing purpose). What is wrong?
Here is a screenshot as well

PHP Solr connection issue

I have PHP-Solr extension version 1.0.3-alpha installed on my server. I'm initializing the connection using:
$options = array(
'hostname' => 'hostname',
'login' => '',
'password' => '',
'port' => '',
'path' => 'solr/core1');
$client = new SolrClient($options);
It returns the following object:
class SolrClient#17 (1) { private $_hashtable_index => int(13444) }
But whenever I try to run a query like:
$qryArray = 'key_id:123456';
$client->deleteByQuery($qryArray);
It throws an exception as follows:
Solr HTTP Error 7: 'Couldn't connect to server
Can anyone help me to find what would causing this issue?
I have tried var_dump($client->getDebug());, but it returns NULL.

Uncaught exception 'Swift_TransportException' with message 'Connection could not be established with host [Operation timed out #60]

I'm using Silex SwiftmailerServiceProvider.
Now i need to send an email from my website but i keep getting this error.
I searched all over the place but i find only the #110 errors etc.
The code i'm using at the moment:
$message = \Swift_Message::newInstance()
->setSubject('[OFFERTE]' . $data['name'])
->setFrom(array('fromemail'))
->setTo(array('myemail'))
->setBody($data['comment'],'text/html');
$app['mailer']->send($message);
This code above is the code inside my page.php (landing page).
$app->register(new Silex\Provider\SwiftmailerServiceProvider(), array(
'swiftmailer.options' => array(
'host' => 'host',
'port' => 'port',
'username' => 'username',
'password' => 'password',
'encryption' => null,
'auth_mode' => null
)
));
The code above here is what's in my bootstrap.php (if you're familiar with silex).
Anyone an idea what might be the source of this error?
Thanks!
Pieter-Jan
EDIT: i did fill in the host etc in boostrap.php
For all others who are having the same issue i had...
If you're getting this message you are doing something wrong. The problem i was having is that some data was wrong to make the connection. So triple check the data you need.

PHP Loop to Access MySQL Databases

I'm trying to figure out how to code a loop in a PHP script that:
gets $hostname, $username $password and $platform from an included script for a bunch of MySQL databases (different remote servers with different access credentials) I just have read-only access to
runs the PHP script on each of the databases
I have all the variables stored in an array that looks like this:
$servers = array(
'server1' => array(
'hostname' => '<serverurl>'
'username' => 'readonly',
'password' => 'pword',
'platform' => 'platform'
),
'server2' => array(
'hostname' => 'serverurl'
'username' => 'readonly',
'password' => 'pword',
'platform' => 'platform'
),
},
I'm having trouble figuring out how to pass those values into a loop statement in my PHP script though - how would I make it run on every server in the array?:
$dbhandle = mysql_connect($hostname, $username, $password) or die(mysql_error('Unable to connect to MySQL'));
echo 'Connected to MySQL<br>';
mysql_select_db($platform, $dbhandle) or die(mysql_error('Unable to connect to database'));
echo 'Connected to database<br>';
Sorry for the noob question/if this is a repeat - I couldn't find anything similar when I searched. Is there a good site for me to look up this sort of thing? Thanks!
<?php
$dbhandles = array();
foreach($servers as $server => $details) {
$dbhandles[$server] = mysql_connect($details['hostname'], $details['username'], $details['password']) or die(mysql_error('Unable to connect to MySQL'));
}

Cake php Datasource class MySQL could not be found

I have ubuntu 10.04 on server.
I am trying to set up the cake php project but it gives me following error
Cake is NOT able to connect to the database.
Datasource class MySQL could not be found.
I have searched lot on the web regarding it.
my config file looks like this
class DATABASE_CONFIG {
public $default = array(
'datasource' => 'Database/MySQL',
'persistent' => false,
'host' => 'localhost',
'login' => 'root',
'password' => 'mypassword',
'database' => 'dbname',
'prefix' => '',
//'encoding' => 'utf8',
);
}
I checked that server has all the things set up to connect as PDO I have run following script and it works fine.
$conn = new PDO('mysql:host=localhost;dbname=dbname', $username, $password);
Then further I have changed in Mysql.php file of cake php which is in the "lib\Cake\Model\Datasource\Database"
I tried to give static connection in Mysql.php but this also doesn't work. I did exit in the Mysql.php and seems like control of page is not getting here.
$this->_connection = new PDO('mysql:host=localhost;dbname=dbname', $username, $password);
$this->connected = true;
Please do let me know if I am missing anything.
Thanks in Advance.
Casing matters, it should be:
'datasource' => 'Database/Mysql'
And not:
'datasource' => 'Database/MySQL'
Mysql is not a supported source try 'datasource' => 'Database/Sqlite',

Categories