PHP 7+ & PDO SQLSRV charset issue - php

PHP 7.2.8
PHP 5.6.37
Same code, different version of PHP. Many have the same problem than I have read.
Did someone finally find the solution?
Thanx in advance.
PS: I have tried with Medoo lib and without lib. Same problem.
Connection File:
require_once __DIR__ . '/config.php';
use Medoo\Medoo;
/* Connection to lin2db database */
$lin2db = new Medoo([
'database_type' => 'mssql',
'database_name' => $CONFIG['lin2db'],
'server' => $CONFIG['MSSQL_addr'],
'username' => $CONFIG['username'],
'password' => $CONFIG['password'],
'charset' => 'utf8'
]);
Query:
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../engine/DB_connection.php';
GLOBAL $lin2db;
$rows = $lin2db->select("user_auth", [
"account",
"password"
], [
"account" => 'builder'
]);
var_dump($rows);
Solution:
var_dump(bin2hex($rows));

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

Database created with doctrine, not shown in phpmyadmin

I am following the tutorial for Doctrine: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/tutorials/getting-started.html
I changed the bootstrap file to include my database to:
<?php
// bootstrap.php
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
require_once "vendor/autoload.php";
// Create a simple "default" Doctrine ORM configuration for Annotations
$isDevMode = false;
$paths = array(__DIR__."/src");
$config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode);
// or if you prefer yaml or XML
//$config = Setup::createXMLMetadataConfiguration(array(__DIR__."/config/xml"), $isDevMode);
//$config = Setup::createYAMLMetadataConfiguration(array(__DIR__."/config/yaml"), $isDevMode);
// database configuration parameters
$conn = array(
'host' => '*********',
'port' => '3306',
'user' => '********',
'password' => '****',
'dbname' => 'bugs',
'charset' => 'UTF8',
'driver' => 'pdo_sqlite',
'path' => __DIR__ . '/db.sqlite',
);
// obtaining the entity manager
$entityManager = EntityManager::create($conn, $config);
Then, I did the rest and create the tables, etc using the following commnad:
vendor/bin/doctrine orm:schema-tool:create
Later, I logged to my 'myphpadmin' and the database was not there.
Am I missing any step?
Thank you
That is because you are using the driver pdo_sqlite. It is creating an SQLite database and not a MySQL database. It should have created the file db.sqlite.
Change it to pdo_mysql to get the database to show up in phpmyadmin.

PDO Exception:SQLSTATE[HY000] [2006] MySQL server has gone away with xampp

I'm trying to connect to the database and fetching some records but I'm getting error:
Error i'm getting
I'm using Slim PHP framework and slim-twig to render views so my code for the connection file is:
<?php
use Payment\App;
use Illuminate\Database\Capsule\Manager as Capsule;
session_start();
require __DIR__ . '/../vendor/autoload.php';
$app = new App;
$capsule = new Capsule;
$capsule->addConnection([
'driver' => 'mysql',
'host' => 'localhost:8080',
'database' => 'payment',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => ''
]);
$capsule->setAsGlobal();
$capsule->bootEloquent();
require __DIR__ . '/../app/routes.php';
?>
I had also configured my php.ini file properties like max_execution_time & max_allowed_packets but it didn't work and i had also checked that no loop is causing this problem because it takes approx 3 min to show me this error,in this 3 min the it loads.so please anyone can tell me where i'm doing in my code?
Probably caused by your packets. The following settings should help:
Run this in your MySQL terminal.
set global max_allowed_packet=104857600

phalcon framework webtools not working when creating models, views and controllers

I'm having some problems while trying to get phalcon webtools working.
When using command line devtools I can create controllers and models without problems.
However, things aren't that easy with the webtools.
It correctly shows already created controllers and models:
Controllers (http://i.imgur.com/IRWPaVJ.png)
Models (http://i.imgur.com/rIbvbg9.png)
And I can also edit them (http://i.imgur.com/orJweLl.png).
Apparently, Db connexion is ok, since webtools shows every table in the DB:
Models (http://i.imgur.com/iOkZfyo.png)
Scaffolding (http://i.imgur.com/5ZLRuq5.png)
However, when trying to create a controller from the web interface, I got the next error:
"Please specify a controller directory"
Same when trying to create a Model from a database table :
"Database configuration cannot be loaded from your config file"
Or when trying to generate scaffold :
"Adapter was not found in the config. Please specify a config variable
[database][adapter]"
My app/config/config.php content:
return new \Phalcon\Config(array(
'database' => array(
'adapter' => 'Mysql',
'host' => 'localhost',
'username' => 'phalcon',
'password' => 'phalcon',
'dbname' => 'phalcon',
'charset' => 'utf8',
),
'application' => array(
'controllersDir' => __DIR__ . '/../../app/controllers/',
'modelsDir' => __DIR__ . '/../../app/models/',
'viewsDir' => __DIR__ . '/../../app/views/',
'pluginsDir' => __DIR__ . '/../../app/plugins/',
'libraryDir' => __DIR__ . '/../../app/library/',
'cacheDir' => __DIR__ . '/../../app/cache/',
'baseUri' => '/phalconTest/',
)
));
My public/webtools.config.php content:
define('PTOOLS_IP', '192.168.248.135');
define('PTOOLSPATH', 'C:/phalcon-devtools');
My public/webtools.php:
use Phalcon\Web\Tools;
require 'webtools.config.php';
require PTOOLSPATH . '/scripts/Phalcon/Web/Tools.php';
Tools::main(PTOOLSPATH, PTOOLS_IP);
Im running Phalcon 1.3.4 - Windows x86 for PHP 5.4.0 (VC9)
It seems like a bug in webtools.
Look at vendor/phalcon/devtools/scripts/Phalcon/Builder/Component.php
there is the _getConfig function.
The quick and dirty solution is prepend ../ to path.
You need to change the first line in app/config/config.php
defined('APP_PATH') || define('APP_PATH', realpath('..'));
To add to some of the answers, the editing of configPath by prepending ../ and also some code changes, has forgotten a a little '/' when modelPath has been rtrimmed.
Also, code will be updated and fixed but as of now, one can probably fix the issues by editing your/path/phalcon-devtools/scripts/Phalcon/Builder/Model.php; find
$modelsDir = rtrim(rtrim($modelsDir, '/'), '\\') . DIRECTORY_SEPARATOR;
if ($this->isAbsolutePath($modelsDir) == false) {
$modelPath = $path . DIRECTORY_SEPARATOR . $modelsDir;
} else {
// $modelPath = $modelsDir;
// replace or ADD TO LINE ABOVE so it looks like BELOW:
$modelPath = DIRECTORY_SEPARATOR . $modelsDir;
}
Then Models will work in webtools along with TKF's answer. Enjoy.
Apply changes in webtools.config.php like here:
<?php
if (!defined('PTOOLS_IP'))
define('PTOOLS_IP', '192.168.');
if (!defined('PTOOLSPATH'))
define('PTOOLSPATH', '/path/to/phalcon/devtools');
return array(
'application' => array(
'controllersDir' => __DIR__ . '/../../app/controllers/',
'modelsDir' => __DIR__ . '/../../app/models/',
),
'database' => array(
'adapter' => 'Mysql',
'host' => 'localhost',
'username' => 'usr',
'password' => 'pwd',
'dbname' => 'dbname',
)
);
Somewhat related, I had an issue with the webtools url getting longer and longer .. Eventually I could fix this by adding the word webtools in a replacement for the baseUri in config.php .
<?php ### config.php ... somewhat relevant parts ...
return new \Phalcon\Config([
'database' => [ # ... some things ...
],
'application' => [ # ... some more ...
// This allows the baseUri to be understand project paths that are not in the root directory
// of the webpspace. This will break if the public/index.php entry point is moved or
// possibly if the web server rewrite rules are changed. This can also be set to a static path.
'baseUri' => preg_replace(
'/(public([\/\\\\]))?(index)|(webtools).php$/',
'',
$_SERVER["PHP_SELF"]
),
]
]);

Class not found. New to 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

Categories